package cn.zhiwen.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * 注解实现熔断
 */
@Service
public class HelloService {

    @Autowired
    RestTemplate restTemplate;

    @HystrixCommand(fallbackMethod = "helloFallback")
    public String helloService(){
        return restTemplate.getForEntity("http://springClient01/hello",String.class).getBody();
    }

    @HystrixCommand(commandKey = "命令名称",groupKey = "分组",threadPoolKey = "线程池划分")
    public String annotionDemo(){
        return restTemplate.getForEntity("http://springClient01/hello",String.class).getBody();
    }

    public String helloFallback(){
        return "error";
    }
}
